/**
 * 
 */
package kr.co.insoft.core.service.auth.impl;

import java.util.HashSet;

import kr.co.insoft.core.service.auth.AuthoritiesService;
import kr.co.insoft.framework.config.AuthUtil;
import kr.co.insoft.framework.config.Authorities;
import kr.co.insoft.framework.config.Menus;
import kr.co.insoft.framework.exceptions.ExceptionCode;
import kr.co.insoft.framework.exceptions.ServiceException;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @author IN-SOFT Inc. GoodwillDD(sylee@in-soft.co.kr)
 * 
 */
@Service
public class AuthoritiesServiceImpl implements AuthoritiesService {
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * kr.co.insoft.core.service.auth.AuthoritiesService#getEnabledButtons()
	 */
	@Override
	public HashSet<Authorities> getEnabledButtons(Menus menu)
			throws ServiceException {
		Authentication auths = null;
		try {
			auths = SecurityContextHolder.getContext().getAuthentication();
			Assert.notNull(auths);
		} catch (IllegalArgumentException e) {
		}

		try {
			return AuthUtil.getEnabledMenuAuth(menu, auths.getAuthorities());
		} catch (Exception e) {
			throw new ServiceException(ExceptionCode.SERVICE_EXCEPTION, e);
		}
	}
}
